//:C14:InheritStack.cpp
// Specializing the Stack class
#include "../09/Stack4.h"
#include "../require.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

class StringStack : public Stack
{
    public:
        void push(string *str)
        {
            Stack::push(str);
        }
        string *peek() const
        {
            return (string *)Stack::peek();
        }
        string *pop()
        {
            return (string *)Stack::pop();
        }
        ~StringStack()
        {
            string *top = pop();
            while(top)
            {
                delete top;
                top = pop();
            }
        }
};

int main(void)
{
    ifstream in("InheritStack.cpp");
    assure(in, "InheritStack.cpp");
    string line;
    StringStack textlines;

    while(getline(in, line))
    {
        textlines.push(new string(line));
    }
    string *s;
    while((s = textlines.pop()) != 0)
    {   // No case!
        cout << *s << endl;
        delete s;
    }
}
